﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Indie_Game_Contest
{
    class CInput
    {
        //////////////////////////////////////////////////////////////////////////
        // Data Members
        static CInput instance = new CInput();

        KeyboardState curKeyState;
        KeyboardState prevKeyState;
        GamePadState curGamePadState;
        GamePadState prevGamePadState;

        //////////////////////////////////////////////////////////////////////////
        // Methods
        CInput() { }

        public void Clear()
        {
            prevKeyState = curKeyState;
            prevGamePadState = curGamePadState;
        }
        public void Update()
        {
            prevKeyState = curKeyState;
            prevGamePadState = curGamePadState;

            curKeyState = Keyboard.GetState();
            curGamePadState = GamePad.GetState(PlayerIndex.One);
        }
        public bool KeyPressed(Keys key)
        {
            if (curKeyState.IsKeyDown(key) && prevKeyState.IsKeyUp(key))
                return true;

            return false;
        }
        public bool KeyDown(Keys key)
        {
            return curKeyState.IsKeyDown(key);
        }
        public bool GamePadButtonDown(Buttons button)
        {
            return curGamePadState.IsButtonDown(button);
        }
        public bool GamePadButtonPressed(Buttons button)
        {
            if (curGamePadState.IsButtonDown(button) && prevGamePadState.IsButtonUp(button))
                return true;

            return false;
        }
        
        //////////////////////////////////////////////////////////////////////////
        // Properties
        public static CInput Instance
        {
            get { return instance; }
        }
    }
}
